<script>
import outMain from "@/components/outMain.vue";
import { ElMessage, ElMessageBox } from "element-plus";
import { Enterprise, EnterpriseCheckStatus } from "@/http/api";

export default {
  components: { outMain },
  name: "",
  data() {
    return {
      tableData: [],
      comArr: [],
      statusArr: [
        { label: "全部", value: "" },
        { label: "正常", value: "1" },
        { label: "禁用", value: "2" },
        { label: "已到期", value: "3" },
      ],
      queryData: {
        enterprise_status: "",
        enterprise_name: "",
        page: 1,
        per_page: 10,
      },
      total: 0,
    };
  },
  props: {},
  setup() {},
  methods: {
    addFn(id) {
      this.$router.push({
        path: "/accountCompanyAdd",
        query: { id: id, page: id ? this.queryData.page : undefined },
      });
    },
    detailFn(id) {
      this.$router.push({
        path: "/accountCompanyDetail",
        query: { id: id, page: this.queryData.page },
      });
    },
    questCheck(data) {
      EnterpriseCheckStatus(data).then((res) => {
        if (res.data.code == 1) {
          ElMessage({
            type: "success",
            message: "操作成功",
          });
          this.getData();
        }
      });
    },
    checkStatus(row, type) {
      if (type == 1) {
        ElMessageBox.confirm("确定恢复选择的企业账号吗?", "操作提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }).then(() => {
          let data = {
            enterprise_id: row.enterprise_id,
            enterprise_status: type,
          };
          this.questCheck(data);
        });
      } else {
        ElMessageBox.prompt("确定禁用选择的企业账号吗?", "操作提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }).then((value) => {
          let data = {
            enterprise_id: row.enterprise_id,
            enterprise_status: type,
            jy_reason: value.value,
          };
          this.questCheck(data);
        });
      }
    },
    serchFn() {
      this.queryData.page = 1;
      this.getData();
    },
    getData() {
      Enterprise(this.queryData).then((res) => {
        if (res.data.code == 1) {
          this.tableData = res.data.data.data;
          this.total = res.data.data.total;
        }
      });
    },
  },
  mounted() {},
  async created() {
    this.queryData.page = Number(localStorage.getItem("boot_page")) || 1;

    this.comArr = await this.$getCate.getComList();
    this.getData();
  },
};
</script>
<template>
  <outMain>
    <div class="tableCont">
      <div class="tableName flexCont">
        <div>企业列表（{{ total }}）</div>
      </div>
      <div class="tableSerch">
        <div class="serchLeft">
          <btn value="新增" @ok="addFn"></btn>
        </div>
        <div class="serchRight">
          <el-form class="flexCenter" :inline="true">
            <el-form-item>
              <el-select
                v-model="queryData.enterprise_name"
                filterable
                clearable
                @change="getData"
                placeholder="请输入企业名称"
              >
                <el-option
                  v-for="item in comArr"
                  :key="item.enterprise_id"
                  :label="item.enterprise_name"
                  :value="item.enterprise_name"
                />
              </el-select>
            </el-form-item>
            <el-form-item>
              <el-select
                v-model="queryData.enterprise_status"
                clearable
                @change="getData"
                placeholder="请选择账号状态"
              >
                <el-option
                  v-for="item in statusArr"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
            <btn value="搜索" @click="getData"></btn>
          </el-form>
        </div>
      </div>
      <el-table class="tableMain" :data="tableData" stripe style="width: 100%">
        <el-table-column
          prop="enterprise_number"
          width="100"
          show-overflow-tooltip
          label="企业编号"
        />
        <el-table-column
          prop="enterprise_name"
          show-overflow-tooltip
          width="200"
          label="企业名称"
        />
        <el-table-column
          prop="enterprise_person"
          width="80"
          show-overflow-tooltip
          label="负责人"
        />
        <el-table-column
          prop="staff_sum"
          width="80"
          show-overflow-tooltip
          label="员工账号"
        />
        <el-table-column
          width="140"
          prop="recharge_money"
          show-overflow-tooltip
          label="充值金额"
        >
          <template #default="{ row }">{{ row.recharge_money }}（元）</template>
        </el-table-column>
        <el-table-column
          prop="jlh_coin"
          width="100"
          show-overflow-tooltip
          label="账户鲸币"
        />
        <el-table-column width="80" show-overflow-tooltip label="账号状态">
          <template #default="{ row }">
            <div class="tagGroup">
              <el-tag type="success" v-if="row.enterprise_status == 1"
                >正常</el-tag
              >
              <el-tag type="danger" v-if="row.enterprise_status == 2"
                >禁用</el-tag
              >
              <el-tag type="info" v-if="row.enterprise_status == 3"
                >已到期</el-tag
              >
            </div>
          </template>
        </el-table-column>
        <el-table-column
          prop="create_time"
          show-overflow-tooltip
          label="创建时间"
        />
        <el-table-column
          prop="expiration_time"
          show-overflow-tooltip
          label="到期时间"
        />
        <el-table-column prop="Name" width="170" label="操作">
          <template #default="{ row }">
            <div class="tableCtrl">
              <div
                class="greenText ctrlText"
                @click="detailFn(row.enterprise_id)"
              >
                详情
              </div>
              <div class="blueText ctrlText" @click="addFn(row.enterprise_id)">
                编辑
              </div>
              <div
                class="blueText ctrlText"
                v-if="row.enterprise_status === 2"
                @click="checkStatus(row, 1)"
              >
                恢复
              </div>
              <div
                class="redText ctrlText"
                v-if="row.enterprise_status === 1"
                @click="checkStatus(row, 2)"
              >
                禁用
              </div>
              <div class="blueText ctrlText">加时</div>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <div class="pageCont">
        <el-pagination
          v-model:currentPage="queryData.page"
          v-model:page-size="queryData.per_page"
          background
          layout="total, prev, pager, next, jumper"
          :total="total"
          @size-change="getData"
          @current-change="getData"
        />
      </div>
    </div>
  </outMain>
</template>
<style scoped lang="less"></style>
